package com.mqtt.demo1.listener;

import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MessageListener implements IMqttMessageListener {

    /** 
    * 处理消息
    * @param topic 主题 
    * @param mqttMessage 消息 
    */
    @Override
    public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
        log.info(String.format("MQTT: 订阅主题[%s]发来消息[%s]", topic, new String(mqttMessage.getPayload())));
//        String jsonStr = new String(mqttMessage.getPayload());
//        User user = JSON.parseObject(jsonStr, User.class);
//        System.out.println("user==========>" + user.getDescription());
    }

}
